/*
 * Fichier: BookTree.java
 * Crée le: 13 septembre 2007.
 * Modifié: 14 février 2009.
 * Auteurs: Sébastien ESTIENNE.
 * SiteWeb: http://www.prog-info.org/
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

package javaexos.gui;



import javaexos.controller.BookController;
import javaexos.model.BookModel;
import javaexos.view.BookView;

import javax.swing.JTree;
import javax.swing.ToolTipManager;
import javax.swing.border.EmptyBorder;
import javax.swing.tree.DefaultTreeCellEditor;



/**
 * <p>Arbre donnant la liste des chapitres et des exercices.</p>
 * @author Sébastien ESTIENNE.
 */
public class BookTree extends JTree implements BookView
{
   /** Serial version UID. */
   private static final long serialVersionUID = 1L;

   /** Le contrôleur. */
   @SuppressWarnings("unused")
   private BookController controller = null;


   /**
    * <p>Construit l'application.</p>
    * @param book Les informations d'une livre (chapitres et exercices).
    * @param controller Le contrôleur associé.
    */
   public BookTree(BookModel book, BookController controller)
   {
      super();

      // Initialisation.
      this.controller = controller;

      // Modifie le modèle de l'arbre.
      setModel(new BookTreeModel(book));

      // Modifie le moteur de rendu de l'abre.
      BookTreeCellRenderer renderer = new BookTreeCellRenderer();
      setCellRenderer(renderer);
      
      // Ajoute un éditeur par défaut à l'arbre.
      setCellEditor(new DefaultTreeCellEditor(this, renderer));
      
      // Modifie les propriétés de l'abre.
      ToolTipManager.sharedInstance().registerComponent(this);
      setRootVisible(true);
      setShowsRootHandles(false);
      setRowHeight(20);
      setBorder(new EmptyBorder(3, 3, 3, 3));
   }
}
